<!--{template common/header_ajax}-->
<script type="text/javascript" reload="1">
	var selorg={};
	selorg.add=function(ctrlid,vals){
		if(vals[0].orgid=='other') vals[0].path='{lang please_select_a_organization_or_department}';
		jQuery('#'+ctrlid+'_Menu').html(vals[0].path+' ');
		jQuery('#sel_'+ctrlid).val(vals[0].orgid).trigger('change');
	}
</script>
<div class="modal-header">
  <h4 class="modal-title text-truncate">{lang add_user}</h4>
  <div class="float-end">
    <button type="button" class="modal-fullscreen-btn"><i class="mdi"></i></button>
    <button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
  </div>
</div>
<div class="modal-body">
  <form id="accountform" name="accountform" class="lyear-search-right" action="{MOD_URL}&op=edituser" method="post" onsubmit="account_submit();return false">
    <input type="hidden" name="accountadd" value="true" />
    <input type="hidden" name="uid" value="$uid" />
    <input type="hidden" name="handlekey" value="adduser" />
    <input type="hidden" name="formhash" value="{FORMHASH}" />
    <div id="return_adduser" style="display:none"></div>
    <div class="row mb-3">
      <label for="email" class="col-sm-2">{lang login_email} <span class="text-danger">*</span></label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="email" name="email" value="$user[email]" onblur="checkemail(this.id);" inputmode="email" placeholder="{lang login_email}">
        <p id="emailmore" style="height:1px;margin:0;">&nbsp;</p>
        <span id="chk_email" class="form-text">
          <span id="suc_email"></span><span class="help-msg"></span> {lang adduser_login_email_text}
        </span>
      </div>
    </div>
    <div class="row mb-3">
      <label for="username" class="col-sm-2">{lang username} <span class="text-danger">*</span></label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="username" name="username" placeholder="{lang login_username_placeholder}" value="$user[username]" onblur="checkusername(this.id);">
        <span id="chk_username" class="form-text">
          <span id="suc_username"></span><span class="help-msg"></span> {lang login_username_tips}
        </span>
      </div>
    </div>
    <!-- <div class="row mb-3">
      <label for="nickname" class="col-sm-2">{lang nickname}</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="nickname" name="nickname" placeholder="{lang user_nickname}" value="$user[nickname]" onblur="checknick(this.id);">
        <span id="chk_nickname" class="form-text">
          <span id="suc_nickname"></span><span class="help-msg"></span> {lang user_nickname}，不能用于登录
        </span>
      </div>
    </div> -->
    <div class="row mb-3">
      <label for="phone" class="col-sm-2">{lang phone_number}</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" placeholder="{lang weixin_phone_number}" id="phone" name="phone" value="$user[phone]" inputmode="tel">
        <span id="chk_phone" class="form-text">{lang adduser_phone_number_text}</span>
      </div>
    </div>
    <div class="row mb-3">
      <label for="weixinid" class="col-sm-2">{lang weixin}</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" placeholder="{lang user_weixin}" id="weixinid" name="weixinid" value="$user[weixinid]">
        <span id="chk_weixinid" class="form-text">{lang edituser_weixin_text}</span>
      </div>
    </div>
    <div class="row mb-3">
      <label for="password" class="col-sm-2">{lang user_login_password} <span class="text-danger">*</span></label>
      <div class="col-sm-10">
        <input type="text" class="form-control" name="password" id="password" placeholder="{lang register_password_tips}">
        <span id="chk_password" class="form-text">
          <span id="suc_password"></span>
        <span id="chk_password" class="help-msg"></span>
        </span>
      </div>
    </div>
    <div class="row mb-1">
      <label for="password2" class="col-sm-2">{lang new_password_confirm} <span class="text-danger">*</span></label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="password2" name="password2" placeholder="{lang register_repassword_tips}">
        <span id="chk_password2" class="form-text">
          <span id="suc_password2"></span>
        <span id="chk_password2" class="help-msg"></span>
        </span>
      </div>
    </div>
    <div class="row mb-3">
      <label for="" class="col-sm-2"></label>
      <div class="col-sm-10">
        <button class="btn btn-primary" type="button" onclick="randomPass()">{lang random_password}</button>
      </div>
    </div>
    <div class="row mb-3">
      <label class="col-sm-2">{lang user_status}</label>
      <div class="col-sm-10">
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="radio" id="status1" name="status" checked="checked" value="0">
          <label class="form-check-label" for="status1">{lang normal}</label>
        </div>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="radio" id="status2" name="status" value="1">
          <label class="form-check-label" for="status2">{lang forbidden}</label>
        </div>
        <span class="form-text">{lang adduser_disable_user_text}</span>
      </div>
    </div>
    <div class="row mb-3">
      <label class="col-sm-2" for="groupid">{lang usergroup}</label>
      <div class="col-sm-10">
        <select class="form-select" name="groupid" id="groupid"<!--{if $_G[ 'adminid']!=1}--> disabled="disabled"<!--{/if}-->>
          <!--{loop $_G['cache']['usergroups'] $groupid $group}-->
          <!--{{if !in_array($groupid ,array('2','3','4','5','6','7','8'))}-->
          <option <!--{if $groupid==9}-->selected="selected"<!--{/if}-->value="$groupid">$group['grouptitle']</option>
          <!--{/if}-->
          <!--{/loop}-->
        </select>
        <span class="form-text">{lang group_permission_guide_text}</span>
      </div>
    </div>
    <div class="row mb-3">
      <label for="depart" class="col-sm-2">{lang department_position}&nbsp;[&nbsp;<a href="javascript:;" class="mdi mdi-plus" onclick="addorgsel()" title="{lang add_a_item}"></a>&nbsp;]</label>
      <div class="col-sm-10">
        <div class="input-group mb-3">
          <div id="selorg_container">
          <!--{if $org}-->
          <div class="btn-group p-2">
            <div class="btn-group me-2">
              <div class="btn-group org">
                <button type="button" id="orgid_{$org['orgid']}_Menu" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown">$org[depart]</button>
                <input id="sel_orgid_{$org['orgid']}" type="hidden" name="orgids[]" value="$org['orgid']" onchange="selDepart(this)" />
                <div id="orgid_$orgid_dropdown_menu" class="dropdown-menu org-sel-box" style="width: 300px;height: 300px;" role="menu" aria-labelledby="orgid_{$org['orgid']}_Menu">
                  <iframe name="orgid_{$org['orgid']}_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&template=1&ctrlid=orgid_{$org['orgid']}&nouser=1&moderator=1&range=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
                </div>
              </div>
              <div class="btn-group job">
                <input type="hidden" name="jobids[]" value="0" />
                <a href="javascript:;" data-toggle="dropdown" role="button" _jobid="0" class="dropdown-toggle btn btn-primary jobid"><span>{lang none}</span></a>
                <ul aria-labelledby="drop-depart" role="menu" class="dropdown-menu">
                  <li role="presentation">
                    <a href="javascript:;" class="dropdown-item" tabindex="-1" role="menuitem" _jobid="0" onclick="selJob(this)">{lang none}</a>
                  </li>
                  <!--{loop $org[jobs] $value1}-->
                  <li role="presentation">
                    <a href="javascript:;" class="dropdown-item" tabindex="-1" role="menuitem" _jobid="$value1['jobid']" onclick="selJob(this)">$value1[name]</a>
                  </li>
                  <!--{/loop}-->
                </ul>
              </div>
            </div>
            <!--{if $value['ismoderator']}-->
            <div class="input-group">
              <a href="javascript:;" onclick="delDepart(this)" ttitle="{lang delete}" class="btn btn-outline-danger"><i class="mdi mdi-delete"></i></a>
            </div>
            <!--{/if}-->
          </div>
          <!--{/if}-->
          <div id="nav" class="btn-group p-2">
            <div class="btn-group me-2">
              <div class="btn-group org">
                <button type="button" id="orgid_tpml_Menu" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown">{lang please_select_a_organization_or_department} </button>
                <input id="sel_orgid_tpml" type="hidden" name="orgids[]" value="0" onchange="selDepart(this)" />
                <div id="orgid_tpml_dropdown_menu" class="dropdown-menu org-sel-box" style="width: 300px;height: 300px;" role="menu" aria-labelledby="orgid_tpml_Menu">
                  <iframe name="orgid_tpml_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&template=1&ctrlid=orgid_tpml&nouser=1&moderator=1&range=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
                </div>
            </div>
            <div class="btn-group job">
              <input type="hidden" name="jobids[]" value="0" />
              <a href="javascript:;" data-toggle="dropdown" role="button" _job="0" class="dropdown-toggle btn btn-primary jobid"><span>{lang none}</span></a>
              <ul aria-labelledby="drop-job" role="menu" class="dropdown-menu">
                <li role="presentation">
                  <a href="javascript:;" tabindex="-1" role="menuitem" class="dropdown-item">{lang none}</a>
                </li>
              </ul>
            </div>
            </div>
            <div class="input-group">
              <a href="javascript:;" onclick="delDepart(this)" ttitle="{lang delete}" class="btn btn-outline-danger"><i class="mdi mdi-delete"></i></a>
            </div>
          </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row mb-3">
      <label for="" class="col-sm-2">{lang supervisor_position}</label>
      <div class="col-sm-10">
        <div class="input-group mb-3">
          <div id="selorg_container" class="col-sm-10">
            <div id="upjob">
              <div class="btn-group me-2">
                <div class="btn-group org">
                <button type="button" id="uporgid_Menu" class="btn btn-outline-primary dropdown-toggle" data-toggle="dropdown">{lang please_select_a_organization_or_department}</button>
                <input id="sel_uporgid" type="hidden" name="uporgid" value="0" onchange="selDepart(this)" />
                <div id="uporgid_dropdown_menu" class="dropdown-menu org-sel-box" style="width: 300px;height: 300px;" role="menu" aria-labelledby="uporgid_Menu">
                  <iframe name="uporgid_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&template=1&ctrlid=uporgid&nouser=1&range=1" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true"></iframe>
                </div>
              </div>
              <div class="btn-group job">
                <input type="hidden" name="upjobid" value="0">
                <a href="javascript:;" data-toggle="dropdown" role="button" _jobid="0" class="dropdown-toggle btn btn-primary jobid"><span>{lang none}</span></a>
                <ul aria-labelledby="drop-job" role="menu" class="dropdown-menu">
                  <li role="presentation">
                    <a href="javascript:;" class="dropdown-item" tabindex="-1" role="menuitem" _jobid="0" onclick="selJob(this)">{lang none}</a>
                  </li>
                </ul>
              </div>
            </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mb-3 form-check">
      <input type="checkbox" class="form-check-input" name="sendmail" id="sendmail" value="1">
      <label class="form-check-label" for="sendmail">{lang send_password_user_mailbox}</label>
    </div>
  </form>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-secondary" data-dismiss="modal" aria-label="Close">{lang close}</button>
  <button type="button" class="btn btn-primary" id="adduser_submit" onclick="account_submit()">{lang confirm_add}</button>
</div>
<script type="text/javascript" reload="1">
	var orgsel_html = jQuery('#nav').html();
	var lastusername = '',
    lastnickname = '',
		lastpassword = '',
		lastemail = '',
		lastinvitecode = '',
		stmp = new Array(),
		modifypwd = false;
	var pwlength = 0;
	var strongpw = new Array();
	var ignoreEmail = false;
	checkPwdComplexity(document.getElementById('password'),document.getElementById('password2'), false);

	function account_submit() {
		//判断用户名
		if(jQuery('#email').val() == '') {
			jQuery('#email').focus();
      jQuery('#email').addClass('is-invalid');
			showmessage('{lang login_email_required}', 'danger', 1000, 1);
			return false;
		}
		if(jQuery('#username').val() == '') {
			jQuery('#username').focus();
      jQuery('#username').addClass('is-invalid');
			showmessage('{lang name_will}', 'danger', 1000, 1);
			return false;
		}

		if(jQuery('#password').val() == '') {
			jQuery('#password').focus();
      jQuery('#password').addClass('is-invalid');
			showmessage('{lang none_write_login_password}', 'danger', 1000, 1);
			return false;
		}
		if(jQuery('#password2').val() == '') {
			showmessage('{lang none_write_affirm_password}', 'danger', 1000, 1);
			jQuery('#password2').focus();
      jQuery('#password2').addClass('is-invalid');
			return false;
		}
		if(jQuery('#password').val() != jQuery('#password2').val()) {
			showmessage('{lang profile_passwd_notmatch}', 'danger', 1000, 1);
			jQuery('#password').focus();
      jQuery('#password').addClass('is-invalid');
			return false;
		}
	
		var flag = 0;
		jQuery('#accountform span').each(function(){
			var self=jQuery(this);
			if(self.hasClass('help-msg') && self.html() != '') {
				flag=1;
				return false;
			}
		});
		if(flag) return false;
		//判定微信号和手机
		var phone = jQuery('#phone').val();
		if(phone != '' && phone.match(/^\d+$/) == null) {
      jQuery('#phone').addClass('is-invalid');
			jQuery('#phone').focus();
			showmessage('{lang phone_number_illegal}', 'danger', 1000, 1);
			return false;
		}
		var weixinid = jQuery('#weixinid').val();
		if(weixinid != '' && weixinid.match(/^[a-zA-Z\d_]{5,}$/) == null) {
      jQuery('#weixinid').addClass('is-invalid');
			jQuery('#weixinid').focus();
			showmessage('{lang weixin_illegal}', 'danger', 1000, 1);
			return false;
		}
    showmessage('{lang In_the_save}','','3000',0);
		ajaxpost('accountform', 'ajaxwaitid', 'return_adduser');
		return false;
	}

	function succeedhandle_adduser(url, message, values) {
    hideWindow('orgwindow');
    showmessage(message, 'success', 3000, 1);
    showDetail('$org['orgid']');
	};

	function errorhandle_adduser(msg, values) {
		showmessage(msg, 'danger', 3000, 1);
	}

	jQuery(document).ready(function(e) {
		jQuery('.dropdown-menu li.disabled a').on('click', function() {
			return false;
		});
	});
  function randomPass() {
		var pass = (Math.round(Math.random() * 100000000));
		jQuery('#password').val(pass).trigger('blur');
		jQuery('#password2').val(pass).trigger('blur');
	}
</script>
<!--{template common/footer_ajax}-->